import { axiosGet, axiosPost } from "@/utils/request";
import { AuthLoginRes, CaptchaRes, LoginRes, UserForm } from "../types/user";
import { Res } from "../types/common";

// 用户登录接口
function userLogin(userForm: UserForm): Res<LoginRes> {
  return axiosPost('/auth/login', userForm, { headers: { isToken: false } })
}

export const getCaptchaImage = (): Promise<CaptchaRes> => {
  return axiosGet('/auth/captchaImage', {}, { timeout: 20000 })
}

/**
 * 统一认证授权码登录
 * @param code
 */
export const getAuthToken = (code: string): Res<AuthLoginRes> => {
  return axiosGet(`/auth/getAuthToken/${code}`)
}

export default {
  userLogin,
  getCaptchaImage
}